package niuke;


import java.util.Scanner;

public class 饥饿的小易 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        if(n<0){
            System.out.println(-1);
            return;
        }
        System.out.println(getStep(n));
    }

    public static int getStep(long a){
        int c=1000000007;
        int k=4;
        int count=-1;
        a=a+1;
        for(int i=2;i<300000;i++){
            if((k*a-1)%c==0){
                count=i/3+((i%3)>0?1:0);
                break;
            }
            k=k*2%c;
        }
        return count;
    }
}
